import App from '../App.vue'
import LoginApp from '../views/LoginApp.vue'
import halo from '../views/halo.vue'
import LoginDoubao from '../views/LoginDoubao.vue'
import DataBind from '../views/DataBind.vue'
import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/LoginApp',
    name: 'LoginApp',
    component: LoginApp
  },
  {
    path: '/demo',
    name: 'demo',
    component: App
  },
  {
    path: '/halo',
    name: 'halo',
    component: halo
  },
  {
    path:'/LoginDoubao',
    name:'LoginDoubao',
    component:LoginDoubao
  },
  {
    path: '/DataBind',
    name: 'DataBind',
    component: DataBind
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to, from, next) => {
  // 判断是否已登陆，sessionStorage.getItem('showLogin') === '0'代表了已登录
  // 已登录：isAuthenticated==true，未登录：isAuthenticated==false
  const isAuthenticated = sessionStorage.getItem('showLogin') === '0'
  // 判断目标路由是否为 /LoginDouBao
  if (to.path === '/LoginDouBao') {
    next() // 直接放行
  } else if (!isAuthenticated) {
    next({ path: '/LoginDouBao' })
  } else {
    next()
  }
})
export default router    